package com.jacken.mars.entity.base;

import com.google.gson.Gson;
import com.jacken.mars.commons.enums.ExceptionEnum;
import com.jacken.mars.entity.resp.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author wq
 */
public class ApiRequestSupport {

    private final static Gson GSON = new Gson();


    public static void invokeExceptionWrapper(HttpServletResponse response, ExceptionEnum exceptionEnum)
            throws IOException {
        R json = new R();
        json.setStatus(exceptionEnum.getCode());
        json.setMsg(exceptionEnum.getMessage());
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().write(GSON.toJson(json));
    }
}
